<?php
session_start();
include_once ("../php/connect_mysql.php");
$cid = $_GET['cid'];
$sql = "SELECT * FROM comment_info WHERE cid = $cid";
$result = $conn->query($sql);
//得到当前id的留言内容
if ($result->num_rows > 0) {
    $res = $result->fetch_assoc();
    $comment = $res["comment"];
    $time = $res["time"];
    $uid = $res["id"];
    if($_SESSION['uid']!=$uid || $_SESSION['user_group'] == 'admin'){
        echo "<script>alert('发稿用户不一致！');window.location.href = '../index.php';</script>";
    }
}
else {
    die("无此条留言");
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>PHP留言簿-留言编辑</title>
    <link rel="stylesheet" href="../css/layui.css">
</head>
<body style="background-color: #FAFAFA">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-blue">Guestbook</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
            <li class="layui-nav-item">
                <a href="javascript:;">菜单</a>
                <dl class="layui-nav-child">
                    <dd><a href="../index.php">首页</a></dd>
                    <dd><a href="login_page.php">登录</a></dd>
                    <dd><a href="register_page.php">注册</a></dd>
                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-md-inline-block">
                <a href="">
                    <?php
                    if (isset($_SESSION['username'])) {
                        if(!empty($_SESSION['headpic_path'])){
                            echo '<img src="'.'../'.$_SESSION['headpic_path'].'"
                         class="layui-nav-img">';
                        }
                        else{
                            echo '<img src="../uploads/default.jpeg"
                                     class="layui-nav-img">';
                        }
                        echo $_SESSION['username'];
                    } else
                        echo "未登录"; ?>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="user_info.php">个人信息</a></dd>
                    <dd><a href="../php/logout.php">退出登录</a></dd>
                </dl>
            </li>
        </ul>
    </div>

    <div class="layui-row">

        <div class="layui-body">
            <div class="layui-container">
                <!-- 内容主体区域 -->
                <fieldset class="layui-elem-field layui-field-title">
                    <legend>文章信息</legend>
                </fieldset>
                <div class="layui-row layui-col-space15">
                    <span class="layui-badge layui-bg-blue"><?php echo "文章ID:".$cid?></span>
                    <span class="layui-badge layui-bg-blue"><?php echo "发布日期:".$time?></span>
                    <div class="layui-col-md12">
                        <div class="layui-panel">
                            <div style="padding: 15px;">
                                <form class="layui-form" action="../php/update.php" method="get">
                                    <div class="layui-form-item layui-form-text">
                                        <label class="layui-form-label">修改留言</label>
                                        <input hidden name="cid" value="<?php echo $cid ?>" type="text">
                                        <div class="layui-input-block">
                                            <textarea name="desc" placeholder="请输入内容" class="layui-textarea"><?php echo $comment?></textarea>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">
                                                立即提交
                                            </button>
                                            <button type="reset" class="layui-btn layui-btn-warm">重置</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../layui.js"></script>
<script>
    layui.use(['element', 'layer', 'util'], function () {
        var element = layui.element
            , layer = layui.layer
            , util = layui.util
            , $ = layui.$;
    });
</script>
</body>
</html>